package FileClass;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DeleteFile {
/**	
	// Bai 1
	public static boolean delete(String path) {
		boolean b = false;
		// B1: Duyet thu muc goc
		File rootDir = new File(path);
		// Lay ra danh sach file trong rootDir
		String[] files = rootDir.list();
		// Duyet qua tung file
		for (String s : files) {
			File f = new File(path + File.separator + s);
			if (f.isDirectory()) {
				delete(f.getAbsolutePath());
			} else {
				b = f.delete();
				if (!b)
					return false;
			}
			System.out.println(f.getAbsolutePath());
			System.out.println(s);
		}
		return true;
	}
	// Bai 2
//	public boolean findFirst(String path, String pattern) {
//		boolean b = Pattern.matches("H?a", "Hoa");
//		System.out.println(b);
//
//		return false;
//	}

	public static void main(String[] args) {
		DeleteFile.delete("ROOT");
//		Pattern p = Pattern.compile("H*a");
//		Matcher m = p.matcher("HHHa");
//		System.out.println(m.matches());

	}
	*/
	public boolean Delete(String path) {
		File file = new File(path);
		if (!file.exists())
			return false;
		if (file.isFile())
			return file.delete();
		else {
			File[] list = file.listFiles();
			for (File f : list) {
				Delete(f.getAbsolutePath());

			}
		}

		return file.delete();
	}

	public static void main(String[] args) {
		DeleteFile e = new DeleteFile();
		e.Delete("D:\\hoa");
		

	}
}
